home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / Tickle-4.0 (tcl) / library / edprocs.tcl < prev    next >
Encoding:
Text File  |  1993-11-05  |  2.0 KB  |  72 lines  |  [TEXT/MPS ]

  1. #
  2. # edprocs.tcl --
  3. #
  4. # Tools for Tcl developers. Procedures to save procs to a file and to edit
  5. # a proc in memory.
  6. #------------------------------------------------------------------------------
  7. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  8. #
  9. # Permission to use, copy, modify, and distribute this software and its
  10. # documentation for any purpose and without fee is hereby granted, provided
  11. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  12. # Mark Diekhans make no representations about the suitability of this
  13. # software for any purpose.  It is provided "as is" without express or
  14. # implied warranty.
  15. #------------------------------------------------------------------------------
  16. # $Id: edprocs.tcl,v 2.1 1993/04/07 02:42:32 markd Exp $
  17. #------------------------------------------------------------------------------
  18. #
  19.  
  20. #@package: TclX-developer_utils saveprocs edprocs
  21.  
  22. proc saveprocs {fileName args} {
  23.     set fp [open $fileName w]
  24.     puts $fp "# tcl procs saved on [fmtclock [getclock]]\n"
  25.     puts $fp [eval "showprocs $args"]
  26.     close $fp
  27. }
  28.  
  29. proc edprocs {args} {
  30.     global env
  31.  
  32.     if [info exists env(HOME)] {
  33.         set tmpFilename "$env(HOME):tcldev.[format "%08lX" [now]]"
  34.     } else {
  35.         set tmpFilename ":tmp:tcldev.[format "%08lX" [now]]"
  36.     }
  37.  
  38.     set fp [open $tmpFilename w]
  39.     puts $fp "#"
  40.     puts $fp "# This is a temporary working file."
  41.     puts $fp "# This file is not automatically deleted."
  42.     puts $fp "#"
  43.     puts $fp [eval "showprocs $args"]
  44.     close $fp
  45.  
  46.     if {[info globals TICKLE] != ""} {
  47.         open_file_window $tmpFilename local
  48.     } else {
  49.     if {[info globals MACINTOSH]} {
  50.         puts stdout "Procedures written to file \"$tmpFilename\""
  51.     } else {
  52.         if [info exists env(EDITOR)] {
  53.             set editor $env(EDITOR)
  54.         } else {
  55.             set editor vi
  56.         }
  57.  
  58.         set startMtime [file mtime $tmpFilename]
  59.         system "$editor $tmpFilename"
  60.  
  61.         if {[file mtime $tmpFilename] != $startMtime} {
  62.         source $tmpFilename
  63.         echo "Procedures were reloaded."
  64.         } else {
  65.         echo "No changes were made."
  66.         }
  67.         unlink $tmpFilename
  68.     }
  69.     }
  70.     return
  71. }
  72.